<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- header -->
    <style>
        .tab_key{
            display: flex;
            flex-flow: row nowrap;
            justify-content: flex-start;
            border-bottom: 1px solid #999;
            margin-top: 20px;
        }
        .tab_key div{
            width: 120px;
            height: 40px;
            line-height: 40px;
            text-align: center;
            cursor: pointer;
            background-color: #D9D9D9;
            color: white;
            margin-right: 20px;
            border-radius: 8px;
        }
        .active{
            background-color: #0e84ff !important;
        }
    </style>
    <%@ include file="/WEB-INF/views/include/header.jsp" %>
</head>
<body class="no-skin">
<%--上传成功模态框--%>
<div class="shade" style="display: none;"></div>
<div class="warning" style="display: none;">
    <p class="title"><em></em><span class="close">X</span></p>
    <p class="cont"></p>
    <div class="la-square-jelly-box la-3x">
        <div></div>
        <div></div>
    </div>
</div>
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">

    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">

                <div class="row" id="opera-backed">
                    <h3 class="text-center">经办已反馈</h3>
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <!-- jqGrid表格 -->
                        <button class="btn btn-sm btn-info" id="btn_gridTable0">刷新</button>
                        <table id="gridTable0"></table>
                        <!-- jqGrid工具类 -->
                        <div id="gridPager0"></div>
                        <!-- 查询对话框 -->
                        <div style="display: none;">
                            <div class="row" id="queryDialog0"></div>
                        </div>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div>
                <!-- /section:settings.box -->
                <!-- /.row -->
                <h3 class="text-center">未反馈任务</h3>
                <div class="tab_key">
                    <div class="active">未反馈子任务列表</div>
                    <div>主任务列表</div>
                </div>
                <div class="tab_switch">

                    <%--搜索栏--%>
                    <%-- <div>
                         <input type="text" class="beginTimes form-control date-picker" placeholder="请选择开始时间" title="请选择开始时间"
                                style="width: 210px;display: inline-block;" onchange="searchUnitTable('/taskUnit/noDoneUnit/')">

                         <input type="text" class="endTimes form-control date-picker" placeholder="请选择结束时间" title="请选择结束时间"
                                style="width: 210px;display: inline-block;" onchange="searchUnitTable('/taskUnit/noDoneUnit/')">
                     </div>
                     <div style="margin-top:10px;">
                         <input type="text" style="width: 280px;" class="searchs" placeholder="请输入搜索内容"
                                onchange="searchUnitTable('/taskUnit/noDoneUnit/')">
                         <button class="btn btn-primary search-btns" onclick="searchUnitTable('/taskUnit/noDoneUnit/')">搜索</button>
                         <button class="btn btn-primary resets">重置</button>
                     </div>--%>
                    <%--以上为搜索--%>
                    <div class="row">
                        <div class="col-xs-12">
                            <!-- PAGE CONTENT BEGINS -->
                            <!-- jqGrid表格 -->
                            <button class="btn btn-sm btn-info" id="btn_gridTable">刷新</button>
                            <table id="gridTable"></table>
                            <!-- jqGrid工具类 -->
                            <div id="gridPager"></div>
                            <!-- 查询对话框 -->
                            <div style="display: none;">
                                <div class="row" id="queryDialog"></div>
                            </div>
                            <!-- PAGE CONTENT ENDS -->
                        </div><!-- /.col -->
                    </div>
                </div>
                <div class="tab_switch">
                    <div class="row">
                        <div class="col-xs-12">
                            <!-- PAGE CONTENT BEGINS -->
                            <!-- jqGrid表格 -->
                            <button class="btn btn-sm btn-info" id="btn_gridTabletab">刷新主任务</button>
                            <input type="text" style="width: 280px;" class="searchs" placeholder="请输入搜索内容"
                                   onchange="searchUnitTable('/taskMain/nowMain','#gridTabletab')">
                            <button class="btn btn-primary search-btns" onclick="searchUnitTable('/taskMain/nowMain','#gridTabletab')">搜索</button>
                            <button class="btn btn-primary resets">重置</button>

                            <table id="gridTabletab"></table>
                            <!-- jqGrid工具类 -->
                            <div id="gridPagertab"></div>
                            <!-- 查询对话框 -->
                            <div style="display: none;">
                                <div class="row" id="queryDialogtab"></div>
                            </div>
                            <!-- PAGE CONTENT ENDS -->
                        </div><!-- /.col -->
                    </div>
                </div>
                    <h3 class="text-center">未反馈单位重大事项</h3>
                    <div class="row">
                        <div class="col-xs-12">
                            <!-- PAGE CONTENT BEGINS -->
                            <!-- jqGrid表格 -->
                            <button class="btn btn-sm btn-info" id="btn_gridTable1">刷新</button>
                            <table id="gridTable1"></table>
                            <!-- jqGrid工具类 -->
                            <div id="gridPager1"></div>
                            <!-- 查询对话框 -->
                            <div style="display: none;">
                                    <%--<div class="row" id="queryDialog"></div>--%>
                            </div>
                            <!-- PAGE CONTENT ENDS -->
                        </div><!-- /.col -->
                    </div><!-- /.row -->

                <h3 class="text-center">未反馈单位内部督查事项</h3>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <!-- jqGrid表格 -->
                        <button class="btn btn-sm btn-info" id="btn_gridTable_nb">刷新</button>
                        <table id="gridTable_nb"></table>
                        <!-- jqGrid工具类 -->
                        <div id="gridPager_nb"></div>
                        <!-- 查询对话框 -->
                        <div style="display: none;">
                            <%--<div class="row" id="queryDialog"></div>--%>
                        </div>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
                <h4 class="redTips">温馨提示：双击表格行或者点击"查看" 查看任务列表</h4>
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->

    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>
    <input id="unback-userType" value="<shiro:principal property="userType"/>" type="text" style="display: none">
    <input id="unback-roleId" value="<shiro:principal property="roleId"/>" type="text" style="display: none">


    <%@ include file="/WEB-INF/views/include/dialog.jsp" %>
</div><!-- /.main-container -->
</div>

<!-- footer -->
<%@ include file="/WEB-INF/views/include/footer.jsp" %>
<script src="<s:url value="/assets/js/own.js"></s:url>"></script>

<script type="text/javascript">
    // 基本路径
    var baseUrl = "<s:url value="/tasklist/normalList"></s:url>"

    // jqgrid的表格高度
    var height = 320;
    // jqgrid表格行头的中文
    var colNames  = ['','','任务名称','子事项','承办',"单位类型",'创建',"任务时限", "任务轮次", "任务状态","逾期天数","操作"];
    var colNames1 = ['','','任务名称','子事项','承办',"单位类型",'创建',"任务时限", "任务轮次", "任务状态","逾期天数","操作"];
    var colNames_nb = ['','任务单号','子事项名称','周期类型','时限',"任务期限","承办人",'创建', "任务状态"];


    var colModel = [
        {name: 'sysId', width: 60, hidden: true, key: true},
        {name: 'taskUnitId', width: 60, hidden: true},
        {name: 'taskMainName', index: 'taskMainName', width: 280, editable: true},
        {name: 'taskSubName', index: 'taskSubName', width: 400, editable: true},
        {name: 'deptName', index: 'deptName', width: 150, editable: false},
        {name: 'unitType', index: 'unitType', width: 150, editable: true,formatter:taskTypeFomatter},

        {name: 'createUserName', index: 'createUserName', width: 100, editable: false},
        {name: 'timeLimit', index: 'timeLimit', width: 100, editable: true, },
        // {name: 'score', index: 'score', width: 100, editable: true, },
        {name: 'timeRound', index: 'timeRound', width: 100, editable: true,formatter:timeRoundFormatter},
        {name: 'type', index: 'type', width: 100, editable: true,formatter:typeFormatter},
        {name: 'overdueDay', index: 'overdueDay', width: 100, editable:true,formatter:overdueDayFormatter },
        {name : 'cz', width : 100, align : "center", formatter:feedbackBtnFormatter}
    ];
    var colModel1 = [
        {name: 'sysId', width: 60, hidden: true, key: true},
        {name: 'taskMainId', width: 60, hidden: true, key: true},
        {name: 'taskMainName', index: 'taskMainName', width: 280, editable: true},
        {name: 'taskSubName', index: 'taskSubName', width: 400, editable: true},
        {name: 'deptName', index: 'deptName', width: 150, editable: false},
        {name: 'unitType', index: 'unitType', width: 150, editable: true,formatter:taskTypeFomatter},

        {name: 'createUserName', index: 'createUserName', width: 100, editable: false},

        {name: 'timeLimit', index: 'timeLimit', width: 100, editable: true, },
        // {name: 'score', index: 'score', width: 100, editable: true, },
        {name: 'timeRound', index: 'timeRound', width: 100, editable: true,formatter:timeRoundFormatter},
        {name: 'type', index: 'type', width: 100, editable: true,formatter:typeFormatter},
        {name: 'overdueDay', index: 'overdueDay', width: 100, editable:true,formatter:overdueDayFormatter },
        {name : 'cz', width : 100, align : "center", formatter:feedbackBtnFormatter}
    ];


    var colModel_nb = [
        {name: 'userTaskId', width: 60,hidden: true, key: true},
        {name: 'sysId', width: 60, width:300 },
        {name: 'subTaskName', index: 'subTaskName', width: 450, editable: true},
        {name: 'timeType', index: 'timeType', width: 300, editable: true,formatter:timeTypeValue_wqs},
        {name: 'cycleValue', index: 'cycleValue', width: 300, editable: true},
        {name: 'remindDate', index: 'remindDate', width: 300, editable: true},
        {name: 'userName', index: 'userName', width: 200, editable: true,},

        {name: 'createUserName', index: 'createUserName', width: 200, editable: true},
        {name: 'taskState', index: 'taskState', width: 100, editable: true,formatter:taskStateValue_wqs },


    ];

    function feedbackBtnFormatter1(value, grid, rows, state) {
        console.log(value, grid, rows, state);
        grid.colModel.title=false
        return "<div style='color: #049CE6;display: flex;justify-content: center'>" +
            "<div style='width: 40px;cursor: pointer' title='查看'id='feedbackBtn1'>查看</div>" +
            // "<div style='border-left:1px solid #049CE6;border-right:1px solid #049CE6;width: 40px;cursor: pointer'title='修改'>修改</div>" +
            // "<div style='width: 40px;cursor: pointer' title='删除'>删除</div>" +
            "</div>";
    }


    /*是否攻坚*/
    function crucialUserFormatter(data) {
        if(data){
            return "攻坚作战室"
        }else{
            return "督查组"
        }
    }

    /**
     * 按钮`
     */
    function feedbackBtnFormatter(value, grid, rows, state) {
        grid.colModel.title=false
        return "<div style='color: #049CE6;display: flex;justify-content: center'>" +
            "<div style='width: 60px;cursor: pointer' title='查看记录' id='feedbackBtn'>查看记录</div>" +
            "</div>";
    }

    /**
     * 任务类型格式化
     */
    function taskTypeFomatter(data) {
        switch (data){
            case '1':
                return '牵头';
                break;
            case '2':
                return '协办';
                break;
            case '3':
                return "督办";
                break;
            default:
                return '未知';
        }
    }

    /**
     * 任务时限轮数
     */
    function timeRoundFormatter(data) {
        return "第"+ data + "轮"
    }

    /**
     * 逾期天数
     */
    function overdueDayFormatter(data) {
        data = parseInt(data)
        if(data>0){
            return parseInt(data)+"天"
        }else {
            return ""
        }
    }

    /**e
     * status
     */
    function statusFormatter(data) {
        switch(data) {
                case '0':
                    return '待审批';
                    break;
                case '1':
                    return '审批未通过';
                    break;
                case '2':
                    return '正常';
                    break;
                case '3':
                    return '新反馈';
                    break;
                 case '4':
                    return '已完成';
                    break;
                 case '5':
                    return '退回重办';
                    break;
                default:
                    return '未知';
            }
    }
    /**
     * 任务类型格式化
     */
    function categoryIdFormatter(data) {
        let mz = '';
        $.ajax({
            url:'/taskMain/categoryName/'+data,
            type:"get",
            dataType:'json',
            async:false,
            success:function (data) {
                mz = data.category;
            }
        })
        return mz;
    }

    function innerBackFormatter(data) {
        switch (data){
            case '0':
                return '无反馈';
                break;
            case '1':
                return '新的反馈';
                break;
            default:
                return ' ';
        }
    }
    /**
     * 任务状态格式化
     */
    function typeFormatter(data) {
        switch(data) {
            case '0':
                return '待签收';
                break;
            case '1':
                return '待反馈';
                break;
            case '2':
                return '已反馈';
                break;
            case '3':
                return '退回重办';
                break;
            case '4':
                return '完成';
                break;
            case '5':
                return '已签收';
                break;
            case '7':
                return '回退单-待反馈';
                break;
            case '8':
                return '回退单-已反馈';
                break;
            case '9':
                return '回退单-完成';
                break;
            default:
                return '未知';
        }
    }

    /**
     * 附件格式化
     */
    function fileFormatter(data) {
        if (data == null || data == "") {
            return "无任务附件";
        } else {
            return '<input type="button" value="下载" onclick="downDetail(\'' + data + '\')" \n' +
                ' style="width: 100%; height: 32px;" class="btn-large btn-primary"/>';
        }
    }

    //下载按钮
    function downDetail(id) {
        var url = "/filesUpload/download/" + id;
        window.open(url);
    }
    var rowIds;



    // 经办已反馈jqgrid的具体执行方法 未签收任务
    jqgrid({
        gridTableId: "#gridTable0",
        gridPagerId: "#gridPager0",
        rowNum:10,
        url:'/tasklist/operaList',
        postData:{'type':'2','imp':'0'},
        autoScroll: false,
        shrinkToFit: false,
        multiselect:false,
        rownumbers: true,
        onSelectRow: function (rowid, status) {
            rowIds = rowid;
            //选择当前的行
            var selectedRowValue = $("#gridTable0").jqGrid('getRowData', rowid);
            var types = selectedRowValue.type;//获取任务状态
            //只有已经反馈和待反馈才可以打开
            if (types == "已反馈") {
                $("#comment").attr("disabled", false);
            } else {
                $("#comment").attr("disabled", true);
            }
            if (!status) {
                gridRemoveSelect(rowid);
            } else {
                var flag = false;
                for (var i = 0; i< rowids.length; i++){
                    if(rowids[i] ==  rowid){
                        flag = true;
                        continue;
                    }
                }
                if(!flag){
                    gridAddSelect(rowid);
                }
            }
        },
        loadComplete:function (data) {
            var ids = $("#gridTable0").jqGrid("getDataIDs");
            var rowDatas = $("#gridTable0").jqGrid("getRowData");//获取所有行的数据
            for (var i = 0; i<rowDatas.length;i++){
                if (data.rows[i].overdueDay){
                    $("#"+ids[i]+ " td").css("color","red"); //逾期
                }
            }
        },
        onSelectAll:function (aRowids,status){
            if (!status) {
                aRowids.forEach(function(value,index){
                    gridRemoveSelect(value);
                });
            } else {
                aRowids.forEach(function(value,index){
                    var flag = false;
                    for (var i = 0; i< rowids.length; i++){
                        if(rowids[i] ==  value){
                            flag = true;
                            continue;
                        }
                    }
                    if(!flag){
                        gridAddSelect(value);
                    }
                });
            }
        },
        gridComplete: function () {
            var rowIds = jQuery("#gridTable0").jqGrid('getDataIDs');
            for (var k = 0; k < rowIds.length; k++) {
                var flag = false;
                for (var i = 0; i < rowids.length; i++) {
                    if (rowids[i] == rowIds[k]) {
                        flag = true;
                        continue;
                    }
                }
                if (flag && flag == true) {
                    jQuery("#gridTable0").setSelection(rowIds[k], true);
                }
            }
        },
        ondblClickRow:function (rowid) {
            var rowData = $('#gridTable0').jqGrid('getRowData',rowid).taskUnitId;
            //console.log("未签收子任务详情"+rowData)

            var usertype  = $('#unback-userType').val();
            // console.log(usertype);
            if('1'==usertype){
                parent.openapp("/taskMain/unitDetail/"+rowData,rowid,"任务详情");
            }else {
                parent.openapp("/taskUnit/taskUnitDetail/"+rowData,rowData,"任务详情")

            }
            /**
             * 打开二级页面
             */
            // parent.openapp("/taskUnit/taskUnitDetail/"+rowData,rowData,"任务详情")
        }
    });



    // jqgrid的具体执行方法 未签收任务
    jqgrid({
        gridTableId: "#gridTable",
        gridPagerId: "#gridPager",
        rowNum:10,
        postData:{'type':'1','imp':'0'},
        autoScroll: false,
        shrinkToFit: false,
        multiselect:false,
        rownumbers: true,
        onSelectRow: function (rowid, status) {
            rowIds = rowid;
            //选择当前的行
            var selectedRowValue = $("#gridTable").jqGrid('getRowData', rowid);
            var types = selectedRowValue.type;//获取任务状态
            //只有已经反馈和待反馈才可以打开
            if (types == "已反馈") {
                $("#comment").attr("disabled", false);
            } else {
                $("#comment").attr("disabled", true);
            }
            if (!status) {
                gridRemoveSelect(rowid);
            } else {
                var flag = false;
                for (var i = 0; i< rowids.length; i++){
                    if(rowids[i] ==  rowid){
                        flag = true;
                        continue;
                    }
                }
                if(!flag){
                    gridAddSelect(rowid);
                }
            }
        },
        loadComplete:function (data) {
            var ids = $("#gridTable").jqGrid("getDataIDs");
            var rowDatas = $("#gridTable").jqGrid("getRowData");//获取所有行的数据
            for (var i = 0; i<rowDatas.length;i++){
                if (data.rows[i].overdueDay){
                    $("#"+ids[i]+ " td").css("color","red"); //逾期
                }
            }
        },
        onSelectAll:function (aRowids,status){
            if (!status) {
                aRowids.forEach(function(value,index){
                    gridRemoveSelect(value);
                });
            } else {
                aRowids.forEach(function(value,index){
                    var flag = false;
                    for (var i = 0; i< rowids.length; i++){
                        if(rowids[i] ==  value){
                            flag = true;
                            continue;
                        }
                    }
                    if(!flag){
                        gridAddSelect(value);
                    }
                });
            }
        },
        gridComplete: function () {
            var rowIds = jQuery("#gridTable").jqGrid('getDataIDs');
            for (var k = 0; k < rowIds.length; k++) {
                var flag = false;
                for (var i = 0; i < rowids.length; i++) {
                    if (rowids[i] == rowIds[k]) {
                        flag = true;
                        continue;
                    }
                }
                if (flag && flag == true) {
                    jQuery("#gridTable").setSelection(rowIds[k], true);
                }
            }
        },
        ondblClickRow:function (rowid) {
            var rowData = $('#gridTable').jqGrid('getRowData',rowid).taskUnitId;
            //console.log("未签收子任务详情"+rowData)

            var usertype  = $('#unback-userType').val();
           // console.log(usertype);
            if('1'==usertype){
                parent.openapp("/taskMain/unitDetail/"+rowData,rowid,"任务详情");
            }else {
                parent.openapp("/taskUnit/taskUnitDetail/"+rowData,rowData,"任务详情")

            }
            /**
             * 打开二级页面
             */
           // parent.openapp("/taskUnit/taskUnitDetail/"+rowData,rowData,"任务详情")
        }
    });
    //单位重大事项 表格初始化
    jqgrid({
        gridTableId: "#gridTable1",
        gridPagerId: "#gridPager1",
        url:"/tasklist/normalList",
        postData:{'type':'1','imp':'1'},

        colNames:colNames1,
        colModel:colModel1,
        rowNum:10,
        autoScroll: false,
        shrinkToFit: false,
        multiselect:false,
        rownumbers: true,
        onSelectRow: function (rowid, status) {
            rowIds = rowid;
        },
        ondblClickRow:function (rowid) {
            console.log(rowid);
            var rowData = $('#gridTable1').jqGrid('getRowData',rowid).unitType;
            console.log(rowData);
            if(rowData=='督办'){
                var taskMainIds = $('#gridTable1').jqGrid('getRowData',rowid).taskMainId;
                console.log("rowid"+rowid+"; taskMainId:"+rowData);
                parent.openapp("/taskMain/query2/"+taskMainIds,taskMainIds,'rowData')
            }else {
                parent.openapp("/taskUnit/taskUnitDetail/"+rowid,rowid,rowData)

            }

        }
    });

    /**
     * 单位内部列表
     */
    jqgrid({
        gridTableId: "#gridTable_nb",
        gridPagerId: "#gridPager_nb",
        url:"/tasklist/insideList",
        postData:{'taskState':'1'},
        colNames:colNames_nb,
        colModel:colModel_nb,
        rowNum:10,
        autoScroll: false,
        shrinkToFit: false,
        multiselect:false,
        rownumbers: true,
        onSelectRow: function (rowid, status) {
            rowIds = rowid;
        },
        ondblClickRow:function (rowid) {
            var rowData = $('#gridTable1').jqGrid('getRowData',rowid).unitType;
            console.log(rowData);
            parent.openapp("/insideDept/backView/"+rowid,'insidefreeback',"任务详情")
            /**
             * 打开二级页面
             */
            // parent.openapp("/taskMain/query2/"+rowid,rowid,rowData)

        }
    });


    //点击开二级页面
    $(document).on("click","#feedbackBtn",function(){
        var rowData = $('#gridTable').jqGrid('getRowData',rowIds).taskMainName;
        if (rowData.length >= 4)
        {
            rowData = rowData.substring(0,4) + "...";
        };
        parent.openapp("/taskUnit/taskUnitDetail/"+rowIds,rowIds,rowData);
    });
    //点击开二级页面 重大思想
    $(document).on("click","#feedbackBtn1",function(){
        var rowData = $('#gridTable1').jqGrid('getRowData',rowIds).mainName;
        if (rowData.length >= 4){
            rowData = rowData.substring(0,4) + "...";
        }
        parent.openapp("/taskMain/query2/"+rowIds,rowIds,rowData);
    });
    //清空选中行
    $("#cancelChecked").click(function () {
        $("#gridTable").jqGrid('resetSelection');
        rowids=[];
    });
    var rowids = [];//选中行id
    /**
     * 取消选中
     */
    function gridRemoveSelect(rowid) {
        rowids.remove(rowid);
    }

    /**
     * 添加选中
     */
    function gridAddSelect(rowid) {
        rowids.push(rowid);
    }

    /**
     * 重写Array
     */
    Array.prototype.remove = function (val) {
        var index = this.indexOf(val);
        if (index > -1) {
            this.splice(index, 1);
        }
    };

    /**
     * 重写Array
     */
    Array.prototype.indexOf = function (val) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == val) return i;
        }
        return -1;
    };
    $("#btn_gridTable0").click(function () {
        seachJqgird("#gridTable0", "#formDialog form");
    })
    $("#btn_gridTable").click(function () {
        seachJqgird("#gridTable", "#formDialog form");
    })
    $("#btn_gridTable1").click(function () {
        seachJqgird("#gridTable1", "#formDialog form");
    })
    $("#btn_gridTable_nb").click(function () {
        seachJqgird("#gridTable_nb", "#formDialog form");
    })
    //导出表
    $("#exportTaskNew").click( function () {
        showExcelDialog({
            url: "/project/exportTaskNew?sysIds=",
            tableId: "#gridTable",
            confirmTitle: "确认对话框",
            confirmMessage: "是否确定导出?",
            confirmOk: "确定",
            confirmCancel: "取消",
            successMessage: "删除成功",
            successTitle: "消息对话框",
            failMessage: "导出失败",
            failTitle: "消息对话框",
            errorTitle: "警告提示框",
            errorMessage: "您当前尚未选中一行，请选择后再试",
            errorOk: "确定"
        });

    })


    //重置表单
    function reset() {
        resetForm("#formDialog form");
    }

    //加载查询对话框
    // $("#queryDialog").load(getUrl("filter"));

    //显示查询对话框
    var queryDialog = $("#queryDialog");
    $("#query").click(function () {
        showDialog({
            dialogTitle: '条件搜素',
            dialogBody: queryDialog,
            dialogFoot: "<button type='button' class='btn btn-primary' onclick='query()'>查询</button>" +
            "<button type='button' class='btn btn-pink' onclick='reset()'>重置</button>" +
            "<button type='button' class='btn btn-default' data-dismiss='modal'>关闭</button>"
        });
    });

    //具体查询方法
    function query() {
        var exportData = $('#formDialog form').serialize();
        seachJqgird("#gridTable", "#formDialog form");
        $("#formDialog").modal('hide');
    }

    // 重置创建表单
    function resetCreate() {
        resetForm("#formDialog form");
        // 清除关于会议纪要的内容,及隐藏按钮
        $('#departContent').empty();
        $("#addDepart").css("display", "none");
    }

    // 显示创建对话框
    $("#selectCategory").click(function () {
        loadDialog({
            dialogTitle: '请选择事项类型',
            dialogUrl: getUrl("selectCategory"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="selectCategory()">确认</button>' +
            '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    });

    /**
     * 判断模态框
     */
    function selectCategory() {
        var exportData = ($('#formDialog form').serialize().split("="))[1];
        loadDialog({
            tableId: "#gridTable",
            dialogTitle: "会议纪要",
            dialogUrl: getUrl("form")+exportData,
            dialogFoot: '<button type="button" class="btn btn-success" onclick="modify()">确定</button>' +
            '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
        });
    }

    // 办结评价
    function comment() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("comment"),
            tableId: "#gridTable",
            successMessage: "保存成功",
            successTitle: '保存对话框',
            failMessage: '保存失败',
            failTitle: '消息对话框'
        });
    }

    //详情
    $("#detail").click(function () {
        showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "任务详情",
            dialogUrl: getUrl("taskMainDetail"),
            dialogFoot: ' <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });
    });

    //修改
    function  modify(){
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("create"),
            tableId: "#gridTable",
            successMessage: "保存成功",
            successTitle: '保存对话框',
            failMessage: '保存失败',
            failTitle: '消息对话框'
        });
    }
    //任务流程
    $("#flow").click(function () {
        showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "任务流程",
            dialogUrl: getUrl("flow"),
            dialogFoot: '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });
    });

    //办结评价
    $("#comment").click(function () {
        var ids = jQuery("#gridTable").jqGrid('getGridParam', 'selarrrow');
        if (ids.length == 1) {
            var rowData = jQuery("#gridTable").jqGrid('getRowData', ids);
            /* if (rowData.type != '已反馈') {
                 alertMessage("只有任务状态为已反馈的任务,才可以进行办结评价!");
                 return;
             }*/
        }

        showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "办结评价",
            dialogUrl: getUrl("comment"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="comment()">提交</button>' +
            '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });
    });

    //删除
    $("#delete").click(function () {
        showDeleteDialog({
            url: getUrl("delete"),
            tableId: "#gridTable",
            confirmTitle: "确认对话框",
            confirmMessage: "是否确定删除?",
            confirmOk: "确定",
            confirmCancel: "取消",
            successMessage: "删除成功",
            successTitle: "消息对话框",
            failMessage: "删除失败",
            failTitle: "消息对话框",
            errorTitle: "警告提示框",
            errorMessage: "您当前尚未选中一行，请选择后再试",
            errorOk: "确定"
        });
    });

    /**
     * 弹出消息对话框
     * @param msg
     */
    function alertMessage(msg) {
        msg = msg == null ? '' : msg;
        bootbox.dialog({
            title: "消息对话框",
            message: msg,
            buttons: {
                "danger": {
                    "label": '确定',
                    "className": "btn-sm btn-danger"
                }
            }
        });
    }

    /**
     * 修改
     */
    $("#update").click(function () {
        showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "修改任务",
            dialogUrl: getUrl("update"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="updateModify()">修改</button>' +
            '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });
    })
    function updateModify() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("update"),
            tableId: "#gridTable",
            successMessage: "保存成功",
            successTitle: '保存对话框',
            failMessage: '保存失败',
            failTitle: '消息对话框'
        });
    }
    /**
     * NewlyAdded 新增议题
     */
    function addYt() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("addTaskSub"),
            tableId: "#gridTable",
            successMessage: "保存成功",
            successTitle: '保存对话框',
            failMessage: '保存失败',
            failTitle: '消息对话框'
        });
    }




    function taskStateValue_wqs(data) {
        switch (data){
            case '0':
                return '待签收';
                break;
            case '1':
                return '待反馈';
                break;
            case '2':
                return '已反馈';
                break;
            case '3':
                return '退回重办';
                break;
            case '4':
                return '完成';
                break;
            case '5':
                return '已签收';
                break;
            default:
                return '未知';
        }
    }


    function timeTypeValue_wqs(data) {
        switch (data){
            case 1:
                return '单时限';
                break;

            case 2:
                return '天';
                break
            case 3:
                return '周';
                break;
            case 4:
                return '月';
                break;
            case 5:
                return '季';
                break;
            case 6:
                return '多时限';
                break;

            default:
                return '无效设置';
        }
    }

</script>

<script>
    //单位内部督查


</script>

<script>
    var tab_keys = document.querySelectorAll(".tab_key div")
    var tab_switchs = document.querySelectorAll(".tab_switch")
    tab_switchs[0].style.display = "block"
    tab_switchs[1].style.display = "none"
    for (let i = 0; i < tab_keys.length; i++) {
        tab_keys[i].onclick = function(){
            for (var j = 0; j < tab_switchs.length; j++) {
                tab_switchs[j].style.display = "none"
                tab_keys[j].className = ""
            }
            tab_switchs[i].style.display = "block"
            tab_keys[i].className = "active"
        }
    }

    var theusertype  = $('#unback-userType').val();
    console.log(theusertype+"333333333333")
    if(theusertype!=1){
        tab_keys[0].style.display = "none"
        tab_keys[1].style.display = "none"
    }
    //经办已反馈表格可见性
    var operaBackedShow =$('#unback-roleId').val();
    if('04'==operaBackedShow)
    {
        $('#opera-backed').hide();
    }

    $("#btn_gridTabletab").click(function () {
        seachJqgird("#gridTabletab", "#formDialogtab form");
    })
    // jqgrid的表格高度
    var height = 320;
    // jqgrid表格行头的中文
    var colNamesTab = ['','单号', '任务名称', "事项类型", "办理时限", "状态说明","逾期说明","任务附件"];

    var colModelTab = [
        {name: 'sysId', width: 60, hidden: true, key: true},
        {name: 'sysId', index: 'sysId', width: 250,hidden: true, editable: true},
        {name: 'mainName', index: 'mainName', width: 250, editable: true},
        {name: 'categoryId', index: 'categoryId', width: 250, editable: true, formatter: categoryIdFormatter},
        {name: 'timeLimit', index: 'timeLimit', width: 250, editable: true},
        {name: 'typeExplain', index: 'typeExplain', width: 250, editable: true },
        {name: 'overdueExplain', index: 'overdueExplain', width: 250, editable: true},
        {name: 'file', index: 'file', width: 250, editable: true, formatter: fileFormatter}
    ];
    // jqgrid的具体执行方法 未签收任务
    jqgrid({
        gridTableId: "#gridTabletab",
        gridPagerId: "#gridPagertab",
        url:'/taskMain/nowMain',
        colNames:colNamesTab,
        colModel:colModelTab,
        rowNum:10,
        postData:{'type':'0','imp':'0'},
        autoScroll: false,
        shrinkToFit: false,
        multiselect:false,
        rownumbers: true,
        onSelectRow: function (rowid, status) {
            rowIds = rowid;
            //选择当前的行
            var selectedRowValue = $("#gridTabletab").jqGrid('getRowData', rowid);
            var types = selectedRowValue.type;//获取任务状态
            //只有已经反馈和待反馈才可以打开
            if (types == "已反馈") {
                $("#comment").attr("disabled", false);
            } else {
                $("#comment").attr("disabled", true);
            }
            if (!status) {
                gridRemoveSelect(rowid);
            } else {
                var flag = false;
                for (var i = 0; i< rowids.length; i++){
                    if(rowids[i] ==  rowid){
                        flag = true;
                        continue;
                    }
                }
                if(!flag){
                    gridAddSelect(rowid);
                }
            }
        },
        loadComplete:function (data) {
            var ids = $("#gridTabletab").jqGrid("getDataIDs");
            var rowDatas = $("#gridTabletab").jqGrid("getRowData");//获取所有行的数据
            for (var i = 0; i<rowDatas.length;i++){
                if (data.rows[i].overdueDay){
                    $("#"+ids[i]+ " td").css("color","red"); //逾期
                }
            }
        },
        onSelectAll:function (aRowids,status){
            if (!status) {
                aRowids.forEach(function(value,index){
                    gridRemoveSelect(value);
                });
            } else {
                aRowids.forEach(function(value,index){
                    var flag = false;
                    for (var i = 0; i< rowids.length; i++){
                        if(rowids[i] ==  value){
                            flag = true;
                            continue;
                        }
                    }
                    if(!flag){
                        gridAddSelect(value);
                    }
                });
            }
        },
        gridComplete: function () {
            var rowIds = jQuery("#gridTabletab").jqGrid('getDataIDs');
            for (var k = 0; k < rowIds.length; k++) {
                var flag = false;
                for (var i = 0; i < rowids.length; i++) {
                    if (rowids[i] == rowIds[k]) {
                        flag = true;
                        continue;
                    }
                }
                if (flag && flag == true) {
                    jQuery("#gridTabletab").setSelection(rowIds[k], true);
                }
            }
        },
        ondblClickRow:function (rowid) {
            parent.openapp("/taskMain/query2/"+rowid,rowid,"子任务页面")

        }
    });

    function categoryIdFormatter(data) {
        let mz = '';
        $.ajax({
            url:'/taskMain/categoryName/'+data,
            type:"get",
            dataType:'json',
            async:false,
            success:function (data) {
                mz = data.category;
            }
        })
        return mz;
    }

    function searchUnitTable(url,tableId) {
        console.log(tableId)
        if(tableId==null||tableId==undefined)
        {
            tableId='#gridTable';
        }
        console.log(tableId)

        var beginTime =  $(".beginTimes").val();//获取开始时间
        var endTime =  $(".endTimes").val();//获取结束时间
        var search =  $(".searchs").val();//搜索字段
        var data = {
            search:search,
            startTime:beginTime,
            endTime:endTime
        }

        $(tableId).jqGrid('setGridParam', {
            url: url,
            postData: data, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入
    }
</script>
</body>
</html>